package cn.lutu.lutu.service.impl;

import cn.lutu.lutu.mapper.CartMapper;
import cn.lutu.lutu.mapper.OrderMapper;
import cn.lutu.lutu.pojo.entity.Cart;

import cn.lutu.lutu.pojo.entity.Order;
import cn.lutu.lutu.pojo.vo.OrderVO;
import cn.lutu.lutu.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @date 2023-06-03
 * @author luoyinhan
 * */
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    CartMapper cartMapper;

    @Override
    public int insertOrder(Long cid) {
        Order order=new Order();
        Cart cart= cartMapper.selectById(cid);
        BeanUtils.copyProperties(cart,order);
        order.setCreateTime(new Date());
        order.setTypeId(cart.getTypeId());
        order.setStatus(0);
        return orderMapper.insert(order);
    }

    @Override
    public List<OrderVO> orderList(Long id) {
        return orderMapper.selectAll(id);
    }


}
